<template>
  <div class="wechat">
    <!-- 卡片视图区域 -->
    <div class="wechat_card">
      <!-- 布局 -->
      <el-row :gutter="20" class="wechat_card_head" type="flex">
        <el-col :span="8">
          <!-- 搜索框及添加区域 -->
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getChargeWaysList"
            size="medium"
          >
            <el-button
              size="medium"
              slot="append"
              icon="el-icon-search"
              @click="getChargeWaysList"
            ></el-button> </el-input
        ></el-col>
        <el-button
          size="medium"
          class="btn_head_medium"
          type="primary"
          @click="addDialogVisible = true"
          icon="el-icon-circle-plus-outline"
          >新增</el-button
        >

        <el-button
          size="medium"
          type="danger"
          @click="removeUserByIds"
          icon="el-icon-remove-outline"
          >删除</el-button
        >
          <!-- 表格列筛选 -->
        <div class="tools_head">
          
          <!-- 导出EXCEL -->
          <el-tooltip content="导出excel" placement="bottom">
            <el-button
              size="small"
              icon="el-icon-download"
              style="margin-left: 10px"
              @click="handleDownload"
            ></el-button>
          </el-tooltip>
        </div>
      </el-row>
      <!-- 收费方式列表区域 -->
      <el-table :data="chargeWaysList" style="width: 100%" border stripe  :header-cell-style="{ textAlign: 'center' }"
        :cell-style="{ textAlign: 'center' }" size="small" height="85%">
        <el-table-column type="selection"></el-table-column>
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column prop="name" label="收费方式名"></el-table-column>
        <el-table-column prop="account" label="账户名" ></el-table-column>
        <el-table-column label="操作" width="200px">
          <!-- 作用域插槽 -->
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showEditDialog(scope.row.id)"
            ></el-button>
            <!-- 删除按钮 -->
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="removeUserById(scope.row.id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 添加收费方式的对话框 -->
      <el-dialog
        title="添加收费方式信息"
        :visible.sync="addDialogVisible"
        width="50%"
        @close="addDialogReset"
      >
        <!-- 内容主题区域 -->
        <el-form
          :model="addForm"
          :rules="addFormRules"
          ref="addFormRef"
          label-width="100px"
          label-position="top"
        >
          <el-form-item label="收费方式名（现金，支付宝，微信，银行卡……）" prop="name"><el-input v-model="addForm.name"></el-input></el-form-item>
          <el-form-item label="账户名" prop="account"><el-input v-model="addForm.account"></el-input></el-form-item>
          <el-form-item label="小区id" prop="communityId"><el-input v-model="addForm.communityId"></el-input></el-form-item>
        
          
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="addDialogVisible = false">取 消</el-button>
          <el-button type="primary">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 修改收费方式信息的对话框 -->
      <el-dialog
        title="修改收费方式信息"
        :visible.sync="editDialogVisible"
        width="50%"
        @close="editDialogClosed"
      >
        <el-form
          ref="editFormRef"
          :model="editForm"
          label-width="150px"
          :rules="editFormules"
         
        >
          <el-form-item label="收费方式名（现金，支付宝，微信，银行卡……）" prop="name"><el-input v-model="editForm.name"></el-input></el-form-item>
          <el-form-item label="账户名" prop="account"><el-input v-model="editForm.account"></el-input></el-form-item>
         
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="this.queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 获取收费方式列表的参数对象
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      chargeWaysList: [
        {
          name:'微信',
          account:'菊次郎的夏天',
        },
        {
          name:'支付宝',
          account:'菊次郎的夏天',
        },
        {
          name:'现金',
          account:'菊次郎的夏天',
        },
      ],
      total: 0,
      // 控制添加对话框的显示与隐藏
      addDialogVisible: false,
      // 控制修改对话框的显示与隐藏
      editDialogVisible: false,
      // 添加房产的表单数据
      addForm: {
        name:'',
        account:'',
        communityId:'' 

      },
      // 查询到的编辑收费方式信息
      editForm: {},
      // 添加表单的验证规则对象
      addFormRules: {

      },
      // 修改收费方式信息表单的验证规则
      editFormules: {

      }

    }

  },
  created() {
    this.getChargeWaysList()
  },
  methods: {
    // 获取收费方式档案列表
    getChargeWaysList() {

    },

    // 展示编辑收费方式的对话框
    showEditDialog() {
      this.editDialogVisible = !this.editDialogVisible
    },
    // 根据id删除收费方式
    async removeUserById() {
      // 先弹框询问用户是否确定要删除
      const confirmResult = await this.$confirm('此操作将永久删除该收费方式记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => {
        return err
      })
      // 如果点击取消返回的是字符串cancel
      // 如果点击确认返回的是字符串confirm
      if (confirmResult !== 'confirm') {
        return this.$message.info('取消了删除')
      }
      return this.$message.error('删除收费方式失败')
      // 刷新列表
      this.getChargeWaysList()
    },
    // 监听修改收费方式对话框的关闭事件
    editDialogClosed() {
      this.$refs.editFormRef.resetFields()
    },
    // 监听pagesize改变的事件
    handleSizeChange(newPageSize) {
      // console.log(newPageSize)
      this.queryInfo.pagesize = newPageSize
      // PageSize改变重新拿到收费方式列表
      this.getChargeWaysList()
    },
    // 监听当前页码改变的事件
    handleCurrentChange(newPageNum) {
      // console.log(newPageNum)
      this.queryInfo.pagenum = newPageNum
      this.getChargeWaysList()
    },
    addDialogReset() {
      // 拿到表单的引用进行重置
      this.$refs.addFormRef.resetFields()
    },
  }
}
</script>
<style lang="less" scoped>
</style>